package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.pojo.Goods;
import com.qf.pojo.GoodsType;
import com.qf.service.GoodStyleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/10/2 18:18
 */
@RestController
@RequestMapping("/goodstype")
public class GoodStyleController {

    @Autowired
    GoodStyleService goodStyleService;

    @GetMapping("/goodstypelist")
    public List<GoodsType> findList(){
        List<GoodsType> list = goodStyleService.findList();
        return list;
    }

    @RequestMapping("/getGoodsListByTypeId")
    public ModelAndView findById(
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pageSize",required = false,defaultValue = "4")Integer pageSize,
            @RequestParam(value = "typeId")Integer typeId, ModelAndView view) {
        PageInfo<Goods> byId = goodStyleService.findById(typeId,pageNum,pageSize);
        view.addObject("pageBean",byId);
        view.setViewName("forward:/goodsList.jsp");
        return view;

    }

}